layui.use(['layer','upload','layedit','treeSelect','table','form','laytpl','element'], function(){
    var $ = layui.$
        ,layer = layui.layer
        ,admin = layui.admin
        ,table = layui.table
        ,element = layui.element
        ,form = layui.form
        ,laytpl = layui.laytpl;
    var delFlag = null;
    var treeSelect= layui.treeSelect;//树形下拉框
    var upload = layui.upload;
    var layedit = layui.layedit;
    var _companyId = $.cookie("companyId");
    $("#createBy").val(_companyId);
    //加载产品批次状态
    $.get("/dictionary/list/337dfe93e8c74dd9b879ba7a5130c9d5",function (status) {
        $.each(status.data,function (i,ele) {
            $("#batchStatus").append('<option value="'+ ele.value +'">'+ ele.name +'</option>');
        });
        form.render('select');
    });

    //加载产品列表
    $.get('/produce/listByCreateBy?createBy='+_companyId,function (data) {
        $.each(data.data,function (i,ele) {
            $("#produceId").append('<option value="'+ ele.id +'">'+ ele.name +'</option>');
        });
        form.render('select');
    });

    //添加企业信息
    form.on('submit(add)', function(data){
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        //初始化数据
        $.ajax({
            url: '/produce/batch/add',
            data:data.field,
            type: 'POST',
            success: function (data) {
                if(data.code == 200) {
                    top.layer.close(index);
                    top.layer.msg("添加成功！");
                    layer.closeAll("iframe");
                    //刷新父页面
                    parent.location.reload();
                } else {
                    top.layer.close(index);
                    top.layer.msg("添加失败！");
                }
            },
            error:function () {
                top.layer.close(index);
                top.layer.msg("添加失败！");
            }
        });
        return false;
    });

});

